package BackTrack.万诺;

import org.junit.Test;

import static MyUtils.MHUtils.*;
import static MyUtils.MHMoban.*;

public class 跳跃游戏55_void {
    @Test
    public void test() {
//        int[] A = {2,3,1,1,4};
//        int[] A = {3,2,1,0,4};
        int[] A = {2,0}; // 特： if(nextI<n) { v[nextI]
        System.out.println(canJump(A));
    }

    int[] v;
    int n;
    boolean res_canJumpFinal = false;
    public boolean canJump(int[] nums) {
        v = nums;
        n = v.length;

        int cI=0, curCanMaxJump=v[0], step=1;
        bT(cI, curCanMaxJump, step);
//        return minStep==999?-1:minStep; // min都要处理999无解
        return res_canJumpFinal;
    }

    private void bT(int cI, int curCanMaxJump, int step) {
        //末1 题感
        if (cI>=n ) {
            return;
        }
        //末2 当非0，后面永远有可能 / =0时才是可以判末了
        if(curCanMaxJump==0 && cI+curCanMaxJump<n-1){
            return;
        }

        // 收集
        if(cI == n-1){
            res_canJumpFinal = true;
            return;
        }

        for (int i = 1; i <= curCanMaxJump ; i++) {
            int nextI = cI+i;
            if(nextI<n) { // -> 靠 can format 【神技！】
                bT(nextI, v[nextI], step + 1);
            }
        }
    }
}
